package generator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import misc.Vector3i;

public abstract class DungeonConstruct {
    protected List<DungeonCellFloor> floorCells = new ArrayList<DungeonCellFloor>();
    protected List<DungeonCellWall> wallCells = new ArrayList<DungeonCellWall>();
    
    public void addFloorCell(DungeonCellFloor cell) {
        floorCells.add(cell);
    }

    public void addWallCell(DungeonCellWall cell) {
        wallCells.add(cell);
    }
    
    public void addCells(Collection<DungeonCell> newCells) {
        for(DungeonCell cell : newCells) {
	    if(cell instanceof DungeonCellFloor) {
		if(!floorCells.contains((DungeonCellFloor)cell))
		    floorCells.add((DungeonCellFloor)cell);
	    } else if(cell instanceof DungeonCellWall) {
		if(!wallCells.contains((DungeonCellWall)cell))
		    wallCells.add((DungeonCellWall)cell);
	    }
        }
    }

    public List<DungeonCellFloor> getFloorCells() {
	return floorCells;
    }

    public List<DungeonCellWall> getWallCells() {
	return wallCells;
    }

    public void removeWallCell(DungeonCellWall wallCell) {
	wallCells.remove(wallCell);
    }

    public List<DungeonCell> getCells() {
	List<DungeonCell> cells = new ArrayList<DungeonCell>();
	cells.addAll(floorCells);
	cells.addAll(wallCells);
        return cells;
    }

    public boolean containsWallCell(DungeonCellWall wallCell) {
	return wallCells.contains(wallCell);
    }

    public boolean containsFloorCell(DungeonCellFloor floorCell) {
	return floorCells.contains(floorCell);
    }
    
    public boolean locationOccupied(Vector3i location) {
	for(DungeonCell cell : floorCells) {
	    if(cell.getLocation().equals(location))
		return true;
	}
	for(DungeonCell cell : wallCells) {
	    if(cell.getLocation().equals(location))
		return true;
	}
	return false;
    }
}
